/* -------------------------------------------------------------------------
 *  This file is part of the Cantian project.
 * Copyright (c) 2024 Huawei Technologies Co.,Ltd.
 *
 * Cantian is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *          http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
 *
 * mes_type.h
 *
 *
 * IDENTIFICATION
 * src/mec/mes_type.h
 *
 * -------------------------------------------------------------------------
 */

#ifndef __MES_TYPE_H__
#define __MES_TYPE_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef enum en_mes_command {
    MES_CMD_CONNECT,
    MES_CMD_MSG_ACK,
    MES_CMD_BROADCAST_ACK,
    MES_CMD_PAGE_ACK,
    MES_CMD_INVLDT_REQ,  // ack cmd is MES_CMD_BROADCAST_ACK (for readonly copies) or MES_CMD_INVLDT_ACK
    MES_CMD_INVLDT_ACK,
    MES_CMD_ASK_MASTER,
    MES_CMD_TRY_ASK_MASTER,
    MES_CMD_TRY_ASK_MASTER_ACK,
    MES_CMD_ASK_OWNER,
    MES_CMD_PAGE_READY,
    MES_CMD_MASTER_ACK_NEED_LOAD,
    MES_CMD_MASTER_ACK_ALREADY_OWNER,
    MES_CMD_MASTER_ACK_OWNER,
    MES_CMD_CLAIM_OWNER_REQ,
    MES_CMD_CLAIM_OWNER_REQ_BATCH,
    MES_CMD_RECYCLE_OWNER_REQ,
    MES_CMD_NOTIFY_MASTER_CLEAN_EDP_REQ,  // ask master to notify holders clean edp
    MES_CMD_NOTIFY_CLEAN_EDP_ACK,
    MES_CMD_CLEAN_EDP_REQ,  // notify holder clean edp, ack cmd is MES_CMD_BROADCAST_ACK
    MES_CMD_EDPINFO_REQ,
    MES_CMD_EDPINFO_ACK,
    MES_CMD_REQUEST_LOCK,
    MES_CMD_TRY_REQUEST_LOCK,
    MES_CMD_RELEASE_LOCK,
    MES_CMD_TRY_RELEASE_LOCK,
    MES_CMD_CLAIM_LOCK,
    MES_CMD_CANCLE_LOCK,
    MES_CMD_LOCK_ACK,
    MES_CMD_REQUEST_LATCH_S,
    MES_CMD_REQUEST_LATCH_X,
    MES_CMD_WAIT_TXN,
    MES_CMD_AWAKE_TXN,
    MES_CMD_TXN_ACK,
    MES_CMD_SCN_REQ,
    MES_CMD_TXN_SCN_BROADCAST,
    #ifdef _DEBUG
        NEW_MES_CMD_TXN_SCN_BROADCAST,
    #endif
    MES_CMD_SCN_BROADCAST,
    MES_CMD_LSN_BROADCAST,
    MES_CMD_TXN_INFO_REQ,
    MES_CMD_TXN_INFO_ACK,
    MES_CMD_TXN_SNAPSHOT_REQ,
    MES_CMD_TXN_SNAPSHOT_ACK,
    MES_CMD_TXN_WAIT,
    MES_CMD_PCR_REQ_MASTER,
    MES_CMD_PCR_REQ_OWNER,
    MES_CMD_PCR_REQ,
    MES_CMD_PCR_ACK,
    MES_CMD_CHECK_VISIBLE,
    MES_CMD_CHECK_VISIBLE_ACK,
    MES_CMD_ERROR_MSG,
    MES_CMD_DDL_BROADCAST,
    MES_CMD_DDL_BROADCAST_ACK,
    MES_CMD_GET_VIEW_INFO_REQ,
    MES_CMD_GET_CONVERTING_PAGE_CNT_ACK,
    MES_CMD_GET_VIEW_INFO_ERROR_ACK,
    MES_CMD_BLOCK_FILE,
    MES_CMD_UNBLOCK_FILE,
    MES_CMD_CKPT_TRIGGER,
    MES_CMD_CKPT_TRIGGER_ACK,
    MES_CMD_LOG_SWITCH,
    MES_CMD_LOG_SWITCH_SUCCESS,
    MES_CMD_LOG_SWITCH_FAIL,
    MES_CMD_CREATE_OBJ_NAME_BROADCAST,
    MES_CMD_CREATE_OBJ_NAME_BROADCAST_ACK,
    MES_CMD_GET_LOG_CURR_ASN,
    MES_CMD_GET_LOG_CURR_ASN_ACK,
    MES_CMD_GET_LOG_ASN_BY_LSN,
    MES_CMD_GET_LOG_ASN_BY_LSN_ACK,
    MES_CMD_GET_LOG_CURR_SIZE,
    MES_CMD_GET_LOG_CURR_SIZE_ACK,
    MES_CMD_SET_LOG_CTRL,
    MES_CMD_SET_LOG_CTRL_ACK,
    MES_CMD_BAK_PRECHECK,
    MES_CMD_BAK_PRECHECK_ACK,
    MES_CMD_UNLATCH_LOGFILE,
    MES_CMD_UNLATCH_LOGFILE_ACK,
    MES_CMD_SET_LOG_LSN,
    MES_CMD_SET_LOG_LSN_ACK,
    MES_CMD_BAK_GET_CTRL,
    MES_CMD_BAK_GET_CTRL_ACK,
    MES_CMD_READONLY2X,
    MES_CMD_BTREE_ROOT_PAGE,
    MES_CMD_BROADCAST_DATA,
    MES_CMD_BROADCAST_DATA_ACK,
    MES_CMD_BROADCAST_USER,
    MES_CMD_CLAIM_OWNER_ACK,
    MES_CMD_RELEASE_OWNER_ACK,
    MES_CMD_DTC_VIEW_INFO_REQ,
    MES_CMD_DTC_VIEW_CONVERTING_PAGE_CNT_ACK,
    MES_CMD_DTC_VIEW_BUFFER_CTRL_REQ,
    MES_CMD_DTC_VIEW_BUFFER_CTRL_ACK,
    MES_CMD_DTC_VIEW_INFO_ERROR_ACK,
    MES_CMD_DRC_REMASTER_TASK,
    MES_CMD_ACCEPT_REMASTER_TASK_ACK,
    MES_CMD_DRC_REMASTER_TASK_ACK,
    MES_CMD_MGRT_MASTER_DATA,
    MES_CMD_MGRT_MASTER_DATA_ACK,
    MES_CMD_NOTIFY_REMASTER_STATUS,
    MES_CMD_BROADCAST_TARGET_PART,
    MES_CMD_BROADCAST_REMASTER_DONE,
    MES_CMD_DTC_VIEW_INFO_ACK,
    MES_CMD_JOIN_CLUSTER_DONE,
    MES_CMD_LEAVE_CLUSTER_DONE,
    MES_CMD_SEND_RCY_SET,
    MES_CMD_DEAD_LOCK_TXN,
    MES_CMD_DEAD_LOCK_TXN_ACK,
    MES_CMD_DEAD_LOCK_SID,
    MES_CMD_DEAD_LOCK_SID_ACK,
    MES_CMD_DEAD_LOCK_ROWID,
    MES_CMD_DEAD_LOCK_ROWID_ACK,
    MES_CMD_DEAD_LOCK_CHECK_TABLE,
    MES_CMD_DEAD_LOCK_CHECK_TABLE_ACK,
    MES_CMD_DEAD_LOCK_WAIT_TABLES,
    MES_CMD_DEAD_LOCK_WAIT_SHARED_TABLES,
    MES_CMD_DEAD_LOCK_TABLES_ACK,
    MES_CMD_DEAD_LOCK_WAIT_RM,
    MES_CMD_DEAD_LOCK_GET_RM,
    MES_CMD_DEAD_LOCK_GET_TABLE,
    MES_CMD_DEAD_LOCK_TABLE_ACK,
    MES_CMD_DEAD_LOCK_WAIT_EVENT,
    MES_CMD_DEAD_LOCK_WAIT_EVENT_ACK,
    MES_CMD_DEAD_LOCK_GET_ITL,
    MES_CMD_DEAD_LOCK_GET_ITL_ACK,
    MES_CMD_DEAD_LOCK_CHECK_ITL,
    MES_CMD_DEAD_LOCK_CHECK_ITL_ACK,
    MES_CMD_DEAD_LOCK_SQL,
    MES_CMD_DEAD_LOCK_SQL_ACK,
    MES_CMD_CHECK_DDL_ENABLED,
    MES_CMD_CHECK_DDL_ENABLED_ACK,
    MES_CMD_CKPT_EDP_BROADCAST_TO_MASTER,
    MES_CMD_CKPT_EDP_BROADCAST_TO_OWNER,
    MES_CMD_GDV_PREP_AND_EXEC_REQ,
    MES_CMD_GDV_PREP_AND_EXEC_ACK,
    MES_CMD_GDV_FETCH_ROW_REQ,
    MES_CMD_SEND_PAGE_INFO,
    MES_CMD_SEND_PAGE_INFO_ACK,
    MES_CMD_CKPT_REQ,
    MES_CMD_BAK_RUNNING,
    MES_CMD_BAK_RUNNING_ACK,
    MES_CMD_GDV_FETCH_ROW_ACK,
    // about DDL MSG.
    MES_CMD_PREPARE_DDL_REQ,
    MES_CMD_PREPARE_DDL_RSP,
    MES_CMD_EXECUTE_DDL_REQ,
    MES_CMD_EXECUTE_DDL_RSP,
    MES_CMD_REWRITE_OPEN_CONN_REQ,
    MES_CMD_REWRITE_OPEN_CONN_RSP,
    MES_CMD_COMMIT_DDL_REQ,
    MES_CMD_COMMIT_DDL_RSP,
    MES_CMD_RECOVERY_LOCK_RES,
    MES_CMD_RECOVERY_LOCK_RES_ACK,
    MES_CMD_BROADCAST_CHANGE_STATUS,
    MES_CMD_SEND_RCY_SET_ACK,
    MES_CMD_SEND_RCY_SET_ERR_ACK,
    MES_CMD_INVALID_DD_REQ,
    MES_CMD_INVALID_DD_RSP,
    MES_CMD_INVALID_ALL_DD_REQ,
    MES_CMD_INVALID_ALL_DD_RSP,
    MES_CMD_UPDATE_DD_REQ,
    MES_CMD_UPDATE_DD_RSP,
    MES_CMD_BROADCAST_INVALIDATE_DC,

    // dummy, to compile extproc
    MES_CMD_RPC_REQ,
    MES_CMD_RPC_ACK,
    MES_CMD_DROP_LIB_REQ,
    MES_CMD_DROP_LIB_ACK,
    MES_CMD_CLOSE_MYSQL_CONNECTION_REQ,
    MES_CMD_CLOSE_MYSQL_CONNECTION_RSP,

#ifdef DB_DEBUG_VERSION
    // syncpoint
    MES_CMD_SYNCPOINT_ABORT,
#endif

    MES_CMD_RECYCLE_DLS_MASTER,
    MES_CMD_RECYCLE_DLS_MASTER_ACK,
    MES_CMD_CLEAN_GRANTED_MAP,

    MES_CMD_UPGRADE_CTRL_VERSION,
    MES_CMD_UPGRADE_CTRL_VERSION_ACK,
    MES_CMD_ARCH_SET_REQ,
    MES_CMD_TIME_BROADCAST,
    MES_CMD_BROADCAST_CLUSTER_ROLE,

    MES_CMD_CEIL
} mes_command_t;

#define MES_MAX_BUFFERLIST (4) /* Number of buffers supported by the bufferlist */

typedef struct st_mes_buffer {
    char *buf;  /* data buffer */
    uint32 len; /* buffer length */
} mes_buffer_t;

typedef struct st_mes_bufflist {
    uint16 cnt;
    mes_buffer_t buffers[MES_MAX_BUFFERLIST];
} mes_bufflist_t;

#ifdef __cplusplus
}
#endif

#endif
